// pages/myactivity/activitieslist.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
  imgurl:app.globalData.imgurl,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
 
  },
  setNavigationBarTitle:function (e){
    switch (e.actype) {
      case '1':
        var title = '关注';
        break;
      case '2':
        var title = '参与';
        break;
      case '3':
        var title = '发布';
        break;
    }
  wx.setNavigationBarTitle({
    title: '我'+ title +'的活动',
  })
},
  fabu:function(){
   wx.navigateTo({
     url: '/pages/myactivity/releaseactivity',
   })
  },
  getlist:function(e){
    switch (e.actype) {
      case '1':
        this.getlist1()
        break;
      case '2':
        this.getlist2()
        break;
      case '3':
        this.getlist3()
        break;
    }
  },
  // 我关注的
  getlist1: function () {
    var that = this
    wx.request({
      url: app.globalData.url + 'Card/followhuodong?wxopenid=' + wx.getStorageSync('openId'),
      success: function (res) {
        that.setList(res.data.data)
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  // 我参与的
  getlist2: function () {
    var that = this
    wx.request({
      url: app.globalData.url + 'Card/baominghuodong?wxopenid=' + wx.getStorageSync('openId'),
      success: function (res) {
        that.setList(res.data.data)
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  // 我发布的
  getlist3:function(){
    var that = this
    wx.request({
      url: app.globalData.url + 'Index/index?wxopenid=' + wx.getStorageSync('openId'),
      success: function (res) {
        that.setList(res.data.data)
      },
      complete: function () {
        wx.hideLoading()
      }
    })
  },
  // 刷新列表
  setList:function(list){
    if (!list) {
      var list = []
    }
    for (var i = 0; i < list.length; i++) {
      list[i].hd_tags = list[i].hd_tags.split(',')
    }
    this.setData({
      list: list
    })
  },// 详情
  detail(e) {
    var o = e.currentTarget.dataset
    wx.navigateTo({
      url: '/pages/interaction/detail/activity-detail?id=' + o.id,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    wx.getStorage({
      key: 'hd',
      success: function(res) {
        console.log(res)
        var e = {
          actype: res.data
        }
        that.setNavigationBarTitle(e)
        that.setData(e)
        that.getlist(e)
      },
    })
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})